﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace Maxel
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            SetDoubleBuffer(dataGridView1, true);
        }

        private void button1_Click(object sender, EventArgs e)
        {
           // dataGridView1.Rows.Add();   
            bindingSource1.AddNew();  
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (bindingSource1.Position  <0)
                return;
            if (bindingSource1.Current == null)
                return;
            Frame frame = new Frame();
            frame.Duration = 100;
            frame.StartColor = Color.Red ;
            frame.EndColor = Color.Yellow  ;

            ((Track)(bindingSource1.Current)).Frames.Add(frame);
        }

        public static void SetDoubleBuffer(Control ctrl, bool value)
        {
            //Argument.VerifyNotNull("ctrl", ctrl);

            ControlStyles ctrlStyles = ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.UserPaint;

            Type ctrlType = ctrl.GetType();
            MethodInfo methodInfo = ctrlType.GetMethod("SetStyle", BindingFlags.NonPublic | BindingFlags.Instance);
            methodInfo.Invoke(ctrl, new object[] { ctrlStyles, value });
        }

        private void Column1_SelectedFrameChanged(object sender, SelectedFrameChangedEventArgs e)
        {
            if (e.Frame == null)
                kryptonLabel1.Text = "null";
            else
                kryptonLabel1.Text = ((Frame)e.Frame).Duration.ToString()    ;
        }

        private void Column1_FrameEditing(object sender, FrameEditingEventArgs e)
        {
            String message = "";
             if (e.Frame == null)
               message = "null";
            else
               message = ((Frame)e.Frame).Duration.ToString()    ;

             MessageBox.Show(e.Context + " " + message); 
        }

        private void trackBar1_ValueChanged(object sender, EventArgs e)
        {
            int percents = 0;
            int range = Math.Abs(trackBar1.Minimum) + Math.Abs(trackBar1.Maximum);
            if (trackBar1.Value <= 0)
            {
                percents = (trackBar1.Value + range / 2) * range / 200;
            }
            else
            {
                percents = trackBar1.Value * 20 + 100;

            }
            // tracksControl1.PerformScale(percents);
            label1.Text =  string.Format("Масштаб {0}%", percents);
            //trackEditorControl1.PerformScale(percents);
            Column1.Scale(percents);

        }
    }

    
}
